package com.wcgksoft.controller.att_management;

import com.wcgksoft.common.util.Layui;
import com.wcgksoft.entity.Att_management.Att_management;
import com.wcgksoft.entity.Att_management.Healthy;
import com.wcgksoft.entity.Att_management.Healthy_member;
import com.wcgksoft.entity.Att_management.Healthy_statistics;
import com.wcgksoft.entity.ConstructionTeam.TeamMembers;
import com.wcgksoft.entity.Work_plan.Work_plan_day.Plan_day_info;
import com.wcgksoft.service.Att_management.Att_managementService;
import com.wcgksoft.service.Att_management.HealthyService;
import com.wcgksoft.service.Att_management.Healthy_memberService;
import com.wcgksoft.service.Att_management.Healthy_statisticsService;
import net.sf.json.JSONObject;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.transaction.Transactional;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: 周权
 * @Date: 2020/03/17/13:53
 * @Description:健康模块
 */
@Controller
@RequestMapping(value = "system/healthy")
public class HealthyController {
    @Autowired
    private HealthyService healthyService;
    @Autowired
    private Healthy_statisticsService healthy_statisticsService;
    @Autowired
    private Att_managementService att_managementService;
    @Autowired
    private Healthy_memberService healthy_memberService;

    /*
    * @Author: 周权
    * @Description:显示健康列表
    * @Param:
    * @create: 2020/3/17 15:11
    * @return:
    */
    /*
     * @Author: 周权
     * @Description:考勤系统列表页面layui的table加载数据
     * @Param:
     * @create: 2020/3/11 10:29
     * @return:
     */
    @ResponseBody
    @RequestMapping(value = "findAll")
    public Layui findAll(@RequestParam(value = "a_tid", required = false) Integer a_tid,
                         @RequestParam(value = "e_id", required = false) Integer e_id,
                         @RequestParam(value = "role_id", required = false) Integer role_id,
                         @RequestParam(value = "area_id", required = false) Integer area_id,
                         @RequestParam(value = "page", required = false) Integer page,
                         @RequestParam(value = "limit", required = false) Integer limit,
                         @RequestParam(value = "starttime", required = false) String starttime,
                         @RequestParam(value = "endtime", required = false) String endtime,
                         @RequestParam(value = "h_team", required = false) String h_team) throws ParseException {
        DetachedCriteria criteria = DetachedCriteria.forClass(Healthy.class);
        if (null!=h_team&&!"".equals(h_team)) {
            criteria.add(Restrictions.like("h_team", h_team, MatchMode.ANYWHERE));
        }
        if ((null!=starttime&&!"".equals(starttime)) && (null!=endtime&&!"".equals(endtime))) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date parse = sdf.parse(starttime+" 00:00:00");
            Date parse2 = sdf.parse(endtime+" 23:59:99");
            criteria.add(Restrictions.between("h_createDate", parse, parse2));
        }
        if ((null!=starttime&&!"".equals(starttime)) && (null==endtime||"".equals(endtime))){
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date parse = sdf.parse(starttime+" 00:00:00");
            Date parse2 = sdf.parse("2099-12-01 23:59:99");
            criteria.add(Restrictions.between("h_createDate", parse, parse2));
        }
        if ((null!=endtime&&!"".equals(endtime)) && (null==starttime||"".equals(starttime))){
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date parse = sdf.parse(endtime+" 23:59:99");
            Date parse2 = sdf.parse("1997-12-01 00:00:00");
            criteria.add(Restrictions.between("h_createDate", parse2, parse));
        }
        if(role_id==2){
            criteria.add(Restrictions.eq("h_eid", e_id));
        } else if(role_id==3){
            criteria.add(Restrictions.eq("h_eid", e_id));
            criteria.add(Restrictions.eq("h_area_id", area_id));
        }else if(role_id==4){
            criteria.add(Restrictions.eq("h_id", a_tid));
        }
        criteria.addOrder(Order.asc("h_team"));
        criteria.addOrder(Order.asc("h_createDate"));
        criteria.add(Restrictions.eq("h_status", 0));
        List<Healthy> byConditions = healthyService.findByConditions(criteria,page,limit);
        return Layui.data(0, "查询成功", healthyService.getTotalCount(), byConditions);
    }

    /*
     * @Author: 周权
     * @Description: 健康列表页面的添加/修改
     * @Param:
     * @create: 2020/3/17 14:38
     * @return:
     */
    @ResponseBody
    @RequestMapping(value = "update")
    public Layui update(@RequestParam(value = "data", required = false) String data,
                        @RequestParam(value = "names")String names,
                        @RequestParam(value = "temps")String temps,
                        @RequestParam(value = "temyess")String temyess,
                        @RequestParam(value = "bloods")String bloods,
                        @RequestParam(value = "bloodyess")String bloodyess,
                        @RequestParam(value = "remarks")String remarks) throws ParseException {
        JSONObject param = JSONObject.fromObject(data);
        if (param == null) {
            return Layui.data(1, "请求格式有误", 0, null);
        } else {
            String id1 = String.valueOf(param.get("id"));
            if(null==id1||id1.equals("")){
                Healthy healthy = (Healthy) JSONObject.toBean(JSONObject.fromObject(data), Healthy.class);
                healthy.setH_status(0);
                healthy.setH_yes(0);
                /*String h_blood_yes = String.valueOf(param.get("h_blood_yes"));
                int blood = Integer.parseInt(h_blood_yes);
                String h_temperature_yes = String.valueOf(param.get("h_temperature_yes"));
                int temperature = Integer.parseInt(h_temperature_yes);
                if(blood==1||temperature==1){//血压和体温有一项异常 则标记异常
                    healthy.setH_yes(1);
                }
                if(blood==0&&temperature==0){//血压和体温都无异常 标记未无异常
                    healthy.setH_yes(0);
                }*/
                healthyService.save(healthy);
                if (null!=names){
                    String[] namelist = names.split(",");
                    String[] templist = temps.split(",");
                    String[] temyeslist = temyess.split(",");
                    String[] bloodlist = bloods.split(",");
                    String[] bloodyeslist = bloodyess.split(",");
                    String[] remarklist = remarks.split(",");
                    if (namelist.length>0){
                        for (int i = 0; i < namelist.length; i++) {
                            if ((null==namelist[i]||namelist[i].equals("")||namelist[i]=="")&&(null==templist[i]||templist[i].equals("")||templist[i]=="")&&(null==temyeslist[i]||temyeslist[i].equals("")||temyeslist[i]=="")
                                    &&(null==bloodlist[i]||bloodlist[i].equals("")||bloodlist[i]=="")&&(null==bloodyeslist[i]||bloodyeslist[i].equals("")||bloodyeslist[i]=="")
                                    &&(null==remarklist[i]||remarklist[i].equals("")||remarklist[i]=="")){
                                continue;
                            }else{
                                Healthy_member healthy_member = new Healthy_member();
                                healthy_member.setH_id(healthy.getId());
                                healthy_member.setH_name(namelist[i]);
                                healthy_member.setH_temperature(Double.valueOf(templist[i]));
                                healthy_member.setH_temperature_yes(Integer.parseInt(temyeslist[i]));
                                healthy_member.setH_blood(Double.valueOf(bloodlist[i]));
                                healthy_member.setH_blood_yes(Integer.parseInt(bloodyeslist[i]));
                                healthy_member.setH_remark(remarklist[i]);
                                if(Integer.parseInt(temyeslist[i])==1||Integer.parseInt(bloodyeslist[i])==1){
                                    healthy_member.setH_yes(1);
                                    healthy.setH_yes(1);
                                }else if(Integer.parseInt(temyeslist[i])==0&&Integer.parseInt(bloodyeslist[i])==0){
                                    healthy_member.setH_yes(0);
                                }
                                healthyService.saveMerge(healthy);
                                healthy_memberService.save(healthy_member);
                            }

                        }
                    }
                }

                //查询当前队伍当日是否创建健康统计表
                String h_createDate = String.valueOf(param.get("h_createDate"));
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                Date parse = sdf.parse(h_createDate+" 00:00:00");
                Date parse2 = sdf.parse(h_createDate+" 23:59:99");
                String h_id = String.valueOf(param.get("h_id"));
                int tid = Integer.parseInt(h_id);
                DetachedCriteria criteria = DetachedCriteria.forClass(Healthy_statistics.class);
                criteria.add(Restrictions.between("s_createDate", parse, parse2));
                criteria.add(Restrictions.eq("s_tid", tid));
                List<Healthy_statistics> byConditions = healthy_statisticsService.findByConditions(criteria);
                if(byConditions.size()>0){//已创建健康统计表
                    for(int j =0;j<byConditions.size();j++){
                        Healthy_statistics healthy_statistics = byConditions.get(0);//获得第一个健康统计表 理论上某个队伍当日只有一个健康统计表
//                        Integer s_num = healthy_statistics.getS_num()+1;//当日当前队伍总添加健康人数+1人
//                        healthy_statistics.setS_num(s_num);
                        DetachedCriteria criteria1 = DetachedCriteria.forClass(Healthy_member.class);
                        criteria1.add(Restrictions.eq("h_id", healthy.getId()));
                        List<Healthy_member> byConditionss = healthy_memberService.findByConditions(criteria1);
                        for(int k =0;k<byConditionss.size();k++){
                            Integer h_yes = byConditionss.get(k).getH_yes();
                            if(h_yes==1){
                                Integer s_no_num = healthy_statistics.getS_no_num()+1;//有异常 健康统计表异常人数+1
                                healthy_statistics.setS_no_num(s_no_num);
                                healthy_statisticsService.saveOrUpdate(healthy_statistics);
                            }else{
                                healthy_statisticsService.saveOrUpdate(healthy_statistics);
                            }
                        }
                        /*Integer h_yes = healthy.getH_yes();
                        if(h_yes==1){
                            Integer s_no_num = healthy_statistics.getS_no_num()+1;//有异常 健康统计表异常人数+1
                            healthy_statistics.setS_no_num(s_no_num);
                        }*/
                        Integer s_no_num = healthy_statistics.getS_no_num();
//                        double v = healthy_statistics.getS_num().doubleValue();
                        Integer a_pm_num = byConditionss.size();//在队伍中添加的成员人数
                        if(null!=a_pm_num){
                            double pro = s_no_num/a_pm_num;//异常人数/队伍成员人数=异常率
                            pro = (double) Math.round(pro * 100) / 100;
                            healthy_statistics.setS_proportion(pro);
                            healthy_statisticsService.saveOrUpdate(healthy_statistics);
                        }
                        break;
                    }
                }else{//当日无健康统计表新建属于当前队伍当日的健康统计表
                    Healthy_statistics healthy_statistics = new Healthy_statistics();
                    healthy_statistics.setS_team(healthy.getH_team());
                    healthy_statistics.setS_createDate(healthy.getH_createDate());
                    healthy_statistics.setS_tid(healthy.getH_id());
                    healthy_statistics.setS_eid(healthy.getH_eid());
                    healthy_statistics.setS_project_id(healthy.getH_project_id());
                    healthy_statistics.setS_area_id(healthy.getH_area_id());
                    healthy_statistics.setS_no_num(0);
                    healthy_statisticsService.save(healthy_statistics);
                    DetachedCriteria criteria1 = DetachedCriteria.forClass(Healthy_member.class);
                    criteria1.add(Restrictions.eq("h_id", healthy.getId()));
                    List<Healthy_member> byConditionss = healthy_memberService.findByConditions(criteria1);
                    for(int k =0;k<byConditionss.size();k++){
                        Integer h_yes = byConditionss.get(k).getH_yes();
                        if(h_yes==1){
                            Integer s_no_num = healthy_statistics.getS_no_num()+1;//有异常 健康统计表异常人数+1
                            healthy_statistics.setS_no_num(s_no_num);
                            healthy_statisticsService.saveMerge(healthy_statistics);
                        }else{
                            healthy_statisticsService.saveMerge(healthy_statistics);
                        }
                    }
                    /*Integer h_yes = healthy.getH_yes();
                    if(h_yes==0){
                        healthy_statistics.setS_no_num(0);
                    }else if(h_yes==1){
                        healthy_statistics.setS_no_num(1);
                    }
                    healthy_statistics.setS_num(1);*/
                    DetachedCriteria criteria2 = DetachedCriteria.forClass(Att_management.class);
                    criteria2.add(Restrictions.between("a_createDate", parse, parse2));
                    criteria2.add(Restrictions.eq("a_tid", tid));
                    List<Att_management> byCondition = att_managementService.findByConditions(criteria2);
                    if(byCondition.size()>0){
                        for(int i = 0;i<byCondition.size();i++){
                            healthy_statistics.setAtt_management(byCondition.get(0));
                            if(null!=byCondition.get(0).getA_pm_num()){//下午考勤人数不为空（先完成一天考勤后添加健康的情况） 将下午考勤人数存入健康统计表
                                healthy_statistics.setS_teamnum(byCondition.get(0).getA_pm_num());
                            }
                            break;
                        }
                    }
                    healthy_statisticsService.saveMerge(healthy_statistics);
                    Integer s_no_num = healthy_statistics.getS_no_num();
                    double v = byConditionss.size();
                    double pro = s_no_num/v;
                    pro = (double) Math.round(pro * 100) / 100;
                    healthy_statistics.setS_proportion(pro);
                    healthy_statisticsService.saveMerge(healthy_statistics);
                }
                return Layui.data(0, "添加成功", 1, Layui.addList(healthy));
            }else{
                Healthy healthy = (Healthy) JSONObject.toBean(JSONObject.fromObject(data), Healthy.class);
                healthy.setH_status(0);
                healthyService.saveOrUpdate(healthy);
                String id = String.valueOf(param.get("id"));
                int id11 = Integer.parseInt(id);
                if (null!=names){
                    DetachedCriteria criteria = DetachedCriteria.forClass(Healthy_member.class);
                    criteria.add(Restrictions.eq("h_id", id11));
                    List<Healthy_member> byConditions = healthy_memberService.findByConditions(criteria);
                    if(null!=byConditions){
                        for(Healthy_member healthy_member:byConditions){
                            healthy_memberService.delete(healthy_member);
                        }
                        String[] namelist = names.split(",");
                        String[] templist = temps.split(",");
                        String[] temyeslist = temyess.split(",");
                        String[] bloodlist = bloods.split(",");
                        String[] bloodyeslist = bloodyess.split(",");
                        String[] remarklist = remarks.split(",");
                        if (namelist.length>0){
                            for (int i = 0; i < namelist.length; i++) {
                                if ((null==namelist[i]||namelist[i].equals("")||namelist[i]=="")&&(null==templist[i]||templist[i].equals("")||templist[i]=="")&&(null==temyeslist[i]||temyeslist[i].equals("")||temyeslist[i]=="")
                                        &&(null==bloodlist[i]||bloodlist[i].equals("")||bloodlist[i]=="")&&(null==bloodyeslist[i]||bloodyeslist[i].equals("")||bloodyeslist[i]=="")
                                        &&(null==remarklist[i]||remarklist[i].equals("")||remarklist[i]=="")){
                                    continue;
                                }else{
                                    Healthy_member healthy_member = new Healthy_member();
                                    healthy_member.setH_id(healthy.getId());
                                    healthy_member.setH_name(namelist[i]);
                                    healthy_member.setH_temperature(Double.valueOf(templist[i]));
                                    healthy_member.setH_temperature_yes(Integer.parseInt(temyeslist[i]));
                                    healthy_member.setH_blood(Double.valueOf(bloodlist[i]));
                                    healthy_member.setH_blood_yes(Integer.parseInt(bloodyeslist[i]));
                                    healthy_member.setH_remark(remarklist[i]);
                                    if(Integer.parseInt(temyeslist[i])==1||Integer.parseInt(bloodyeslist[i])==1){
                                        healthy_member.setH_yes(1);
                                        healthy.setH_yes(1);
                                    }else if(Integer.parseInt(temyeslist[i])==0&&Integer.parseInt(bloodyeslist[i])==0){
                                        healthy_member.setH_yes(0);
                                    }
                                    healthyService.saveMerge(healthy);
                                    healthy_memberService.save(healthy_member);
                                }

                            }
                        }
                    }else {
                        String[] namelist = names.split(",");
                        String[] templist = temps.split(",");
                        String[] temyeslist = temyess.split(",");
                        String[] bloodlist = bloods.split(",");
                        String[] bloodyeslist = bloodyess.split(",");
                        String[] remarklist = remarks.split(",");
                        if (namelist.length>0){
                            for (int i = 0; i < namelist.length; i++) {
                                if ((null==namelist[i]||namelist[i].equals("")||namelist[i]=="")&&(null==templist[i]||templist[i].equals("")||templist[i]=="")&&(null==temyeslist[i]||temyeslist[i].equals("")||temyeslist[i]=="")
                                        &&(null==bloodlist[i]||bloodlist[i].equals("")||bloodlist[i]=="")&&(null==bloodyeslist[i]||bloodyeslist[i].equals("")||bloodyeslist[i]=="")
                                        &&(null==remarklist[i]||remarklist[i].equals("")||remarklist[i]=="")){
                                    continue;
                                }else{
                                    Healthy_member healthy_member = new Healthy_member();
                                    healthy_member.setH_id(healthy.getId());
                                    healthy_member.setH_name(namelist[i]);
                                    healthy_member.setH_temperature(Double.valueOf(templist[i]));
                                    healthy_member.setH_temperature_yes(Integer.parseInt(temyeslist[i]));
                                    healthy_member.setH_blood(Double.valueOf(bloodlist[i]));
                                    healthy_member.setH_blood_yes(Integer.parseInt(bloodyeslist[i]));
                                    healthy_member.setH_remark(remarklist[i]);
                                    if(Integer.parseInt(temyeslist[i])==1||Integer.parseInt(bloodyeslist[i])==1){
                                        healthy_member.setH_yes(1);
                                        healthy.setH_yes(1);
                                    }else if(Integer.parseInt(temyeslist[i])==0&&Integer.parseInt(bloodyeslist[i])==0){
                                        healthy_member.setH_yes(0);
                                    }
                                    healthyService.saveMerge(healthy);
                                    healthy_memberService.save(healthy_member);
                                }

                            }
                        }
                    }
                }
               /* Integer h_yes2 = byId1.getH_yes();//未修改前是否异常
                String h_blood_yes = String.valueOf(param.get("h_blood_yes"));
                int blood = Integer.parseInt(h_blood_yes);
                String h_temperature_yes = String.valueOf(param.get("h_temperature_yes"));
                int temperature = Integer.parseInt(h_temperature_yes);
                if(blood==1||temperature==1){//血压异常或者体温异常 标记为异常
                    healthy.setH_yes(1);
                }
                if(blood==0&&temperature==0){//血压和体温都正常 标记为正常
                    healthy.setH_yes(0);
                }
                healthy.setH_status(0);
                healthyService.saveOrUpdate(healthy);*/

                String h_createDate = String.valueOf(param.get("h_createDate"));
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                Date parse = sdf.parse(h_createDate+" 00:00:00");
                Date parse2 = sdf.parse(h_createDate+" 23:59:99");
                String h_id = String.valueOf(param.get("h_id"));
                int tid = Integer.parseInt(h_id);
                DetachedCriteria criteria = DetachedCriteria.forClass(Healthy_statistics.class);
                criteria.add(Restrictions.between("s_createDate", parse, parse2));
                criteria.add(Restrictions.eq("s_tid", tid));
                List<Healthy_statistics> byConditions = healthy_statisticsService.findByConditions(criteria);
                if(byConditions.size()>0){//获得当日当前队伍健康统计表 修改健康表必定已创建健康统计表
                    for(int j =0;j<byConditions.size();j++){
                        Healthy_statistics healthy_statistics = byConditions.get(0);
                        healthy_statistics.setS_no_num(0);
                        healthy_statisticsService.saveMerge(healthy_statistics);
                        DetachedCriteria criteria3 = DetachedCriteria.forClass(Healthy_member.class);
                        criteria3.add(Restrictions.eq("h_id", id11));
                        List<Healthy_member> byConditionss = healthy_memberService.findByConditions(criteria3);
                        for(int k =0;k<byConditionss.size();k++){
                            Integer h_yes = byConditionss.get(k).getH_yes();
                            if(h_yes==1){
                                Integer s_no_num = healthy_statistics.getS_no_num()+1;//有异常 健康统计表异常人数+1
                                healthy_statistics.setS_no_num(s_no_num);
                                healthy_statisticsService.saveMerge(healthy_statistics);
                            }else{
                                healthy_statisticsService.saveMerge(healthy_statistics);
                            }
                        }
                        /*Integer h_yes = healthy.getH_yes();//修改后是否异常
                        if(h_yes2==0&&h_yes==1){//修改前正常 修改后异常 异常总数+1
                            Integer s_no_num = healthy_statistics.getS_no_num()+1;
                            healthy_statistics.setS_no_num(s_no_num);
                        }
                        if(h_yes2==1&&h_yes==0){//修改前异常 修改后正常 异常总数-1
                            Integer s_no_num = healthy_statistics.getS_no_num()-1;
                            healthy_statistics.setS_no_num(s_no_num);
                        }
                        healthy_statisticsService.saveOrUpdate(healthy_statistics);*/
                        Integer s_no_num = healthy_statistics.getS_no_num();
                        double v = byConditionss.size();
                        double pro = s_no_num/v;//异常数/总添加健康人数=异常率
                        pro = (double) Math.round(pro * 100) / 100;
                        healthy_statistics.setS_proportion(pro);
                        healthy_statisticsService.saveOrUpdate(healthy_statistics);
                        break;
                    }
                }
                return Layui.data(0, "修改成功", 1, Layui.addList(healthy));
            }
        }
    }

    /*
    * @Author: 周权
    * @Description: 健康系统删除健康信息
    * @Param:
    * @create: 2020/3/17 16:44
    * @return:
    */
    @ResponseBody
    @RequestMapping(value = "delete")
    public Layui delete(@RequestParam(value = "id") Integer id) {
        Healthy byId = healthyService.findById(id);
        byId.setH_status(1);//设置健康数据状态为1 在列表页隐藏
        healthyService.saveOrUpdate(byId);
        return Layui.data(1, "删除成功", 1, null);
    }

    /*
    * @Author: 周权
    * @Description:查找当前健康表下所有成员健康信息
    * @Param:
    * @create: 2020/3/29 16:52
    * @return:
    */
    @ResponseBody
    @RequestMapping(value = "findHealthymember")
    public Layui findHealthymember(@RequestParam(value = "h_id") Integer h_id) {
        DetachedCriteria criteria = DetachedCriteria.forClass(Healthy_member.class);
        criteria.add(Restrictions.eq("h_id", h_id));
        List<Healthy_member> byConditions = healthy_memberService.findByConditions(criteria);
        return Layui.data(0, "查询成功", healthy_memberService.getTotalCount(), byConditions);
    }

    /*
    * @Author: 周权
    * @Description:查找当日当前施工队伍是否点击健康
    * @Param:
    * @create: 2020/3/30 10:12
    * @return:
    */
    @ResponseBody
    @RequestMapping(value = "findHealthy")
    public Integer findHealthy(@RequestParam(value = "a_tid") Integer a_tid) throws ParseException {
        DetachedCriteria criteria = DetachedCriteria.forClass(Healthy.class);
        criteria.add(Restrictions.eq("h_id", a_tid));

        Date date = new Date();
        Calendar instance = Calendar.getInstance();
        instance.setTime(date);
        int i = instance.get(Calendar.YEAR);
        int i1 = instance.get(Calendar.MONTH)+1;
        int i2 = instance.get(Calendar.DAY_OF_MONTH);
        String s = String.valueOf(i);
        String s1;
        if(i1<10){
            s1 = "0"+String.valueOf(i1);
        }else{
            s1 = String.valueOf(i1);
        }
        String s2;
        if(i2<10){
            s2 = "0"+String.valueOf(i2);
        }else{
            s2 = String.valueOf(i2);
        }
        String s3 = s+"-"+s1+"-"+s2+" 00:00:00";
        String s4 = s+"-"+s1+"-"+s2+" 23:59:99";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date parse1 = sdf.parse(s3);
        Date parse2 = sdf.parse(s4);
        criteria.add(Restrictions.between("h_createDate", parse1, parse2));
        List<Healthy> byConditions = healthyService.findByConditions(criteria);
        if(byConditions.size()>0){
            return 0;
        }else{
            return 1;
        }
    }
}
